<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>table</title>
  </head>
  <body>
    <table border="1">
      <tr>
        <td>1-1</td>
        <td>2-1</td>
        <td>3-1</td>
        <td>4-1</td>
      </tr>
      <tr>
        <td>1-2</td>
        <td>2-2</td>
        <td>3-2</td>
        <td>4-2</td>
      </tr>
      <tr>
        <td>1-3</td>
        <td>2-3</td>
        <td>3-3</td>
        <td>4-3</td>
      </tr>
      <tr>
        <td>1-4</td>
        <td>2-4</td>
        <td>3-4</td>
        <td>4-4</td>
      </tr>
    </table>
    <script>
      var trList = document.querySelectorAll('tr');
      for (var i = 0; i < trList.length; i++) {
        trList[i].cells[i].style.backgroundColor = 'red';
      }
    </script>
  </body>
</html>
